package String;

public class item541 {
    public static String reverseStr(String s, int k) {

        char [] c = s.toCharArray();
        int last =s.length()%(2*k);
        int cur = s.length()/(2*k);
        int start = 0;
        int end = start+k;
        while (end<=cur*2*k) {
              reverse(c, start, end);
              start = start + 2 * k;
              end = start+k;
          }

//      这一段写关于剩下的咋办的
        int l = c.length-(start);

        if(l<k)
        {
            reverse(c,start,start+l);
        }else
        {
            reverse(c,start,start+k);
        }
        String res= new String(c);
        return res;
    }

    private static void reverse(char []c, int start, int end) {
        int left =start;
        int right = end-1;
        while (left<=right)
        {
            char tmp = c[left];
            c[left] =c[right];
            c[right] = tmp;
            left++;
            right--;
        }
    }

    public static void main(String[] args) {
        String str =  "abcdefg";
        String s = reverseStr(str, 1);
        System.out.println(s);

    }
}
